package com.itheima.api.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.pms.PmsProductAttributeValueMapper;
import com.itheima.vo.pojo.PmsMemberPrice;
import com.itheima.vo.pojo.PmsProductAttributeValue;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeValueServiceImpl extends ServiceImpl<PmsProductAttributeValueMapper, PmsProductAttributeValue> implements PmsProductAttributeValueService {

    @Autowired
    private PmsProductAttributeValueMapper Mapper;

    @Override
    public boolean saveById(long pid, List<PmsProductAttributeValue> List) {
        //计数器
        int flag = 0;

        for (PmsProductAttributeValue p : List) {
            p.setProductId(pid);
            Mapper.insert(p);
            flag += 1;
        }

        return flag == List.size();
    }

    @Override
    public boolean updateWithId(Integer id, List<PmsProductAttributeValue> List) {

        //计数器
        int flag = 0;

        for (PmsProductAttributeValue p : List) {
            p.setProductId(id);
            Mapper.updateById(p);
            flag += 1;
        }

        return flag == List.size();
    }

    @Override
    public List<PmsProductAttributeValue> getWithId(Integer id) {
        LambdaQueryWrapper<PmsProductAttributeValue> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsProductAttributeValue::getId,id);
        return Mapper.selectList(lqw);
    }
}
